package com.example.studyktdemo.viewmodel

import androidx.lifecycle.MutableLiveData
import com.example.studyktdemo.bean.CateGoryResponse
import com.example.studyktdemo.bean.RankingListResponse
import com.example.studyktdemo.constants.Constants.BASE_URL
import com.example.studyktdemo.interfaces.RetrofitApi
import com.example.studyktdemo.uitls.RetrofitManager
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class RankListViewModel {

    var rankListLiveData = MutableLiveData<RankingListResponse>()

    //获取排行榜信息
    fun getRankList(){
        val request: RetrofitApi = RetrofitManager().retrofit.
                                    create(RetrofitApi::class.java)
        val call: Call<RankingListResponse> = request.rankList
        call.enqueue(object : Callback<RankingListResponse> {
            override fun onResponse(call: Call<RankingListResponse>, response: Response<RankingListResponse>) {
                if (response.body() != null) {
                    rankListLiveData.postValue(response.body())
                }
            }

            override fun onFailure(call: Call<RankingListResponse>,e: Throwable) {
                TODO("Not yet implemented")
            }
        })
    }
}